package com.xiashitech.agent.boot;

import java.io.IOException;
import java.util.jar.JarFile;

/**
 * 类加载拦截的帮助类
 */
public class LoadClassHelper {

    private static JarFile jarFile;

    private static String agentPath;

    public static void init(String agentPath)throws IOException {
        LoadClassHelper.agentPath = agentPath;
        LoadClassHelper.jarFile = new JarFile(agentPath, false);
    }

    public static String getAgentPath() {
        if(agentPath == null) {
            throw new Error("The agent's path is null!");
        }
        return agentPath;
    }

    public static JarFile getJarFile() {
        if(jarFile == null) {
            throw new Error("The agent jar cannot be found!");
        }
        return jarFile;
    }

    /**
     * 如果某些类需要被加载到当前ClassLoader，而不是PlatformClassLoader，返回false可实现过滤
     */
    public static boolean toPlatformLoader(String className) {
        return true;
    }

}
